#include "ObserverEvents.h"
#include "Subject.h"
#include "ConsoleEvents.h"
#include "WorkZone.h"
#include <iostream>

using namespace std;

void ObserverEvents::update(Subject * value)
{
	ConsoleEvents * a = (ConsoleEvents*)value;

	if (a->first_second)
	{
		Zone()->GetArm(0)->getLinkFirst().add(a->d1);
		Zone()->GetArm(0)->getLinkSecond().add(a->d2);
		a->d1 = a->d2 = 0;
		Zone()->GetArm(0)->modifyAngleFirst (a->my * 90 / 25);
		Zone()->GetArm(0)->modifyAngleSecond(a->mx * 180 / 80);

	}
	else
	{
		Zone()->GetArm(1)->getLinkFirst().add(a->d1);
		Zone()->GetArm(1)->getLinkSecond().add(a->d2);
		a->d1 = a->d2 = 0;
		Zone()->GetArm(1)->modifyAngleFirst (180-(a->my * 90 / 25));
   		Zone()->GetArm(1)->modifyAngleSecond(360-(a->mx * 180 / 80));
	}

	
	Alarm()->NotifyAll();// Call Observers of Alarm
	
	if (Alarm()->GetArmsInZone()==2)
		Zone()->NotifyAll(); // Call Observers of Zone	
	

}